package com.leetcode.Offer;

public class JZ04_2 {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int a = 0, b = matrix[0].length - 1;

        while (a < matrix.length && b >= 0) {
            if (target > matrix[a][b]) {
                a++;
            } else if (target < matrix[a][b]) {
                b--;
            } else {
                return true;
            }
        }
        return false;
    }
}
